﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Event_SG_EWDT
{
    public partial class CreateGroup : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["Member"] == null)
            {
                Session["flag"] = "redirecterror";
                Response.Redirect("~/registration.aspx");
            }
        }

        protected void btnCreateGroup_Click(object sender, EventArgs e)
        {
            string groupId = GroupControl.CreateGroup(Session["Member"].ToString(),tbxCreateGroupName.Text,tbxCreateGroupDesc.Text,rdblCreateGroupPrivacy.SelectedIndex,Convert.ToInt32(ddlCreateGroupCat.SelectedValue),Session["Member"].ToString());

            if (groupId != null)
            {
                if (fuCreateGroupLogo.HasFile)
                {
                    Utility.UploadGroupLogo(fuCreateGroupLogo, groupId);
                }
                else
                {
                    Utility.UploadDefaultLogo(groupId);
                }

                if (fuCreateGroupThumbnail.HasFile)
                {
                    Utility.UploadGroupThumbnail(fuCreateGroupThumbnail, groupId);
                }
                else 
                {
                    Utility.UploadDefaultGroupThumbnail(groupId);
                }

                //Utility.UploadGroupPoster(Server, fuCreateGroupLogo, groupId);
                //Utility.UploadGroupThumbnail(Server, fuCreateGroupLogo, groupId);

                ScriptManager.RegisterStartupScript(this, this.GetType(), "toast", "$().toastmessage('showSuccessToast', 'Yay! Group has been created!');", true);

                //should redirect to the new group....

                Session["flag"] = "newcreated";
                Response.Redirect("~/ViewGroup.aspx?groupid=" + groupId);
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "toast", "$().toastmessage('showErrorToast', 'Opps! Opps! One or more required field was not valid!');", true);
            }


        }
    }
}